package com.zhuiyun.project.api.dict.controller;

import com.zhuiyun.project.api.dict.model.DictTypeModel;
import com.zhuiyun.project.api.dict.service.impl.DictTypeServicerImpl;
import com.zhuiyun.project.common.errorCode.CommonException;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.util.pageUtil.PageRequest;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName DictTypeController
 * @Description TODO
 * @Author Root
 * @Date 2023/6/20 11:09
 **/
@RestController
@Api(tags = "用户管理")
@RequestMapping("/dictType")
@Slf4j
@CrossOrigin
public class DictTypeController {
    @Autowired
    DictTypeServicerImpl dictTypeService;

    /**
     * @param pageRequest
     * @param dictTypeModel
     * @Author Root
     * @Description 分页查询字典类型信息
     * @Date 2023/6/20 16:49
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @GetMapping("/selectDictByPage")
    CommonResult selectDictByPage(PageRequest pageRequest, DictTypeModel dictTypeModel) {
        return dictTypeService.selectDictByPage(pageRequest, dictTypeModel);
    }

    /**
     * @param dictTypeModel
     * @Author Root
     * @Description 修改字典类型信息
     * @Date 2023/6/20 16:49
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @PostMapping("/updateDict")
    public CommonResult updateDict(DictTypeModel dictTypeModel) {
        return dictTypeService.updateDict(dictTypeModel);
    }

    /**
     * @param dictId
     * @Author Root
     * @Description 删除字典类型信息
     * @Date 2023/6/20 21:25
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @DeleteMapping("/deleteById")
    public CommonResult deleteById(Integer dictId) throws CommonException {
        return dictTypeService.deleteById(dictId);
    }

    /**
     * @param dictTypeModel
     * @Author Root
     * @Description 添加字典类型信息
     * @Date 2023/6/21 9:19
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @PostMapping("/insertDict")
    public CommonResult insertDict(DictTypeModel dictTypeModel) throws CommonException {
        return dictTypeService.insertDict(dictTypeModel);
    }

    /**
     * @param dictName
     * @Author Root
     * @Description 字典模糊查询
     * @Date 2023/6/21 14:18
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @GetMapping("/selectLike")
    public CommonResult selectLike(String dictName) {
        return dictTypeService.selectLike(dictName);
    }
}
